
import { HTTP } from "@/tools";
import { PagingQuery, StandardPagingResult, StandardResponse } from "./standard";

export interface GetSystemRoleQuery extends Partial<PagingQuery> {
  name: string,
  code: string,
}
export interface SystemRoleListItem {
  code: string,
  createTime: string,
  createUser: number,
  dataScopeType: number,
  id: string,
  name: string,
  remark: string,
  sort: number,
  status: number,
  tenantId: string,
  updateTime: string,
  updateUser: number
}
export async function GetSystemRoles(params: Partial<GetSystemRoleQuery>) {
  return HTTP.post<StandardResponse<StandardPagingResult<SystemRoleListItem>>>('/sysRole/page', params)
}
export async function SystemRolesDelete(params: { id: string }) {
  return HTTP.post('/sysRole/delete', params)
}
export async function GetSystemRolesOwnData(params: { id: number }) {
  return HTTP.post<StandardResponse<string | number[]>>('/sysRole/ownData', params)
}
export interface SystemGrantDataInfo {
  id: number,

  grantOrgIdList: []
}
/**
 * 授予角色
 * 数据权限
 * @param params 
 * @returns 
 */
export async function GrantSystemRolesDataScope(params: SystemGrantDataInfo) {
  return HTTP.post('/sysRole/grantData', params)
}


export interface IEditInfo {
  id?: string;
  name: string;
  code: string;
  sort: number;
  dataScopeType: string;
  remark?: string;
}

export async function SaveRoleInfo(params: IEditInfo) {
  const { id, ...otherinfo } = params
  return HTTP.post("/sysRole/" + (id ? "edit" : "add"), id ? params : otherinfo)
}

export async function GetRoleGrantMenus(params: { id: string }) {
  return HTTP.post<StandardResponse<string[]>>('/sysRole/ownMenu', params)
}
export interface GrantSystemMenuData {
  id: string,
  grantMenuIdList?: string[],
}
/**
 * 授予角色菜单权限
 * 
 * @param params 
 * @returns 
 */
export async function GrantRoleMenus(params: GrantSystemMenuData) {
  return HTTP.post<StandardResponse<string[]>>('/sysRole/grantMenu', params)
}